package com.sun.hunk.hibernate.dao;

import com.sun.hunk.hibernate.BaseHibernateDAO;
import com.sun.hunk.hibernate.domain.Link;
import com.sun.hunk.hibernate.domain.LinkTree;
import com.sun.hunk.hibernate.domain.impl.DomainFactory;
import com.sun.hunk.hibernate.domain.impl.LinkTreeImpl;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;

/**
 *
 * @author sunil
 */
public class LinkTreeDAO extends BaseHibernateDAO<LinkTreeImpl> {

    public LinkTreeDAO() {
        super(LinkTreeImpl.class);
    }
    private static Logger log = Logger.getLogger(LinkTreeDAO.class);

    public Map<Link, Set<Link>> getMainMenu() {
        Map<Link, Set<Link>> menu = new HashMap<Link, Set<Link>>();
        for (LinkTree itemTree : findAll()) {
            if (itemTree.getParent().getProgram() != null) {
                continue;
            }
            Set<Link> set = menu.get(itemTree.getParent());
            if (set == null) {
                set = new HashSet<Link>();
                menu.put(itemTree.getParent(), set);
            }
            set.add(itemTree.getChild());
        }
        return menu;
    }

    public List<LinkTree> getTabs(Long parentId) {
        Link item = DomainFactory.getLink(parentId);
        return (List<LinkTree>) findByProperty("parent", item);
    }
}
